<?php
namespace Models;
class Task extends Model {

    public function create($data) {
        $sql = 'insert into tasks(content, complete_date) 
        values ("' . $data['content'] . '", "' . $data['complete_date']. '")';
        return $this->pdo->exec($sql);
    }
    public function getAll() {
        $sql = 'select * from tasks order by id desc';
        $stmt = $this->pdo->query($sql);
        return $stmt->fetchAll(\PDO::FETCH_ASSOC);
    }
    public function deleteById($id) {
        $sql = 'delete from tasks where id = ' . $id;
        return $this->pdo->exec($sql);
    }
    public function getTaskById($id) {
        $sql = 'select * from tasks where id = ' . $id;
        $stmt = $this->pdo->query($sql);
        return $stmt->fetch(\PDO::FETCH_ASSOC);
    }
    public function updateById($data, $id) {
        $sql = 'update tasks set content = "' . $data['content'] . '", complete_date="'
            . $data['complete_date'] . '" where id = ' . $id;
        return $this->pdo->exec($sql);
    }
}